﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace HexTileBoard
{
    public class DynamicText : DrawableGameComponent
    {
        SpriteBatch spriteBatch;
        public List<DynamicTextLine> DynamicTextLines = new List<DynamicTextLine>();

        public DynamicText(Game game) : base(game)
        {}

        public override void Initialize()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        public override void Update(GameTime gameTime)
        {
            for (int i = 0; i <  DynamicTextLines.Count; i++)
            {
                DynamicTextLines[i].Update(gameTime);
                if (DynamicTextLines[i].LifeExpired > DynamicTextLines[i].LifeLength)
                    DynamicTextLines.RemoveAt(i);
            }
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            for (int i = 0; i < DynamicTextLines.Count; i++)
            {
                spriteBatch.DrawString(DynamicTextLines[i].Font, DynamicTextLines[i].Text, new Vector2(DynamicTextLines[i].Position.X + 2, DynamicTextLines[i].Position.Y + 2), DynamicTextLines[i].ShadowColor * DynamicTextLines[i].AlphaValue, 0.0f, DynamicTextLines[i].Origin, DynamicTextLines[i].Scale, SpriteEffects.None, 0);
                spriteBatch.DrawString(DynamicTextLines[i].Font, DynamicTextLines[i].Text, DynamicTextLines[i].Position, DynamicTextLines[i].Color * DynamicTextLines[i].AlphaValue, 0.0f, DynamicTextLines[i].Origin, DynamicTextLines[i].Scale, SpriteEffects.None, 0);
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
